//
//  CommonNavigationController.m
//  HXBaseProjectDemo
//
//  Created by YaSha_Tom on 2018/2/1.
//  Copyright © 2018年 亚厦装饰股份有限公司. All rights reserved.
//

#import "CommonNavigationController.h"

@interface CommonNavigationController ()<YSChangingThemeDelegate>

@property (nonatomic, assign) BOOL isWhite;

@end

@implementation CommonNavigationController

- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
    UIViewController *returnController = [super popViewControllerAnimated:YES];
    return returnController;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        _isWhite = viewController.preferredStatusBarStyle == UIStatusBarStyleLightContent ? YES : NO;
        viewController.navigationItem.leftBarButtonItem = [self rt_customBackItemWithTarget:self action:@selector(popViewControllerAnimated:)];
    }
    
    [super pushViewController:viewController animated:animated];
}

- (UIBarButtonItem *)rt_customBackItemWithTarget:(id)target action:(SEL)action {
    UIImage *image = _isWhite ? UIImageMake(@"返回白") : UIImageMake(@"返回");
    UIImage *backImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    return [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStyleDone target:target action:action];
}

- (void)handleThemeChangedNotification:(NSNotification *)notification {
    NSObject<YSThemeProtocol> *themeBeforeChanged = notification.userInfo[YSThemeBeforeChangedName];
    themeBeforeChanged = [themeBeforeChanged isKindOfClass:[NSNull class]] ? nil : themeBeforeChanged;
    
    NSObject<YSThemeProtocol> *themeAfterChanged = notification.userInfo[YSThemeAfterChangedName];
    themeAfterChanged = [themeAfterChanged isKindOfClass:[NSNull class]] ? nil : themeAfterChanged;
    
    [self themeBeforeChanged:themeBeforeChanged afterChanged:themeAfterChanged];
}

#pragma mark - <YSChangingThemeDelegate>

- (void)themeBeforeChanged:(NSObject<YSThemeProtocol> *)themeBeforeChanged afterChanged:(NSObject<YSThemeProtocol> *)themeAfterChanged {
#warning todo 更新
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.rt_disableInteractivePop = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
